require.config({baseUrl: '/js/lib', urlArgs: "v0.0.1"});
require(["zepto", "lib", 'swiper'], function ($, lib, swiper) {
    lib = new lib();
    var fn = {};
    $.extend(fn, {
        init: function () {
            this.initPage();
            this.bindEvent();
        },
        initBanner: function (data) {
            new swiper('.ui-banner', {
                autoplay: 5000, //可选选项，自动滑动
                pagination: '.swiper-pagination',
                preventLinksPropagation: true,
                onSlideChangeStart: function (swiper) {
                    var current_num = swiper.activeIndex;
                    $('#current_page').html(current_num + 1);
                    $('#recommet_title').html(data[current_num].title);
                    $('#recommet_info').html(data[current_num].digest);
                }
            });
        },
        bindEvent: function () {
            var _t = this;
            $(document).on('tap', '.ui-per-goods', function () {
                if($(this).attr('type') == '1'){
                    location.href = '/school/knowledge.html?classid=' + $(this).attr('classid');
                }else{
                    location.href = '/school/off_line_activity.html?classid=' + $(this).attr('classid');
                }
            });
        },
        initPage: function () {
            var _t = this;
            //轮播图
            lib.ajx(lib.getReq().ser + 'classroom/getRecommend.action', {}, function (data) {
                if (data.infocode === "0") {
                    $('#total_page').html(data.info.length);
                    $('#recommet_title').html(data.info[0].title);
                    $('#recommet_info').html(data.info[0].digest);
                    $('#current_page').html('1');
                    var b = '<div class="swiper-wrapper">';
                    $.each(data.info, function (k, v) {
                        b += `<div class="swiper-slide">
                        <a href="/school/knowledge.html?classid=${v.classroomId}"><img class="lazy" src="${lib.getReq().imgPath + v.picture}" /></a>
                </div>`
                    });
                    b += '</div><div class="swiper-pagination"></div>';
                    $(".ui-banner").html(b);
                    _t.initBanner(data.info);
                } else {
                    lib.showMessage(data.info);
                }
            }, function () {
                lib.showMessage('网络延时，请稍后再试');
            });

            //课堂列表
            lib.ajx(lib.getReq().ser + 'classroom/getList.action', {pageNo: 1, pageSize: 99}, function (data) {
                if (data.infocode === "0") {
                    var html = '';
                    $.each(data.info, function (k, v) {
                        html += `<li class="ui-per-goods" classid="${v.classroomId}" type="${v.type}">
                            <ul>
                              <li><img class="lazy" src="${lib.getReq().imgPath + v.picture}" ></li>
                              <li>
                                <p>${v.title}</p>
                                <p>${v.digest}</p>
                                <p><span class="${v.type == '1' ? 'ui-ff9130' : ''}">${v.type == '1' ? '知识讲堂' : '线下活动'}</span><span>${v.createDate}</span></p>
                              </li>
                            </ul>
                          </li>`
                    });
                    $("#class_list").html(html);
                } else {
                    lib.showMessage(data.info);
                }
            }, function () {
                lib.showMessage('网络延时，请稍后再试');
            });
        }
    });
    fn.init();
});
